package com.wenhao.leetcode.medium;

/**
 * 题目:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/
 * 删除有序数组中的重复项 II
 * @author Wenhao Tong
 * @create 2021-07-12 12:42
 */
public class LeetCode80 {
    public static void main(String[] args) {

    }
    public int removeDuplicates(int[] nums) {
        // 从1开始，因为第一个是一定不会被删除的
        int index = 1;
        boolean flag = true;
        for (int i = 1;i < nums.length;i++) {
            if (nums[i] != nums[i - 1]) {
                nums[index++] = nums[i];
                continue;
            }
            if (flag) {
                nums[index++] = nums[i];
                flag = false;
            }
        }
        return index;
    }
}
